<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../js/vue.js"></script>
  <style>
    .base{
      list-style-type: none;
      cursor: pointer;
    }

    .active {
      color: red;
    }
  </style>
</head>

<body>

  <!-- 需求:点击列表中的哪一项,那么该项的文字变成红色 -->
  <div id ="app">
    <ul>
      <li v-for="(item,index) in movies"  class="base" :class="{active:index === currentIndex}" @click="handleClick(index)">{{item}}</li>
    </ul>
  </div>

  <script>
   var vm = new Vue({
    el: '#app',
    data: {
      movies:['星际穿越','哈利波特','盗梦空间','海尔兄弟','黑猫警长','火影忍者'],
      currentIndex:''
    },
    methods: {
      handleClick:function(index){
        console.log(index);
        this.currentIndex = index
      }
    }
   });
  </script>
</body>

</html>